package Server.UI.InterfacceDefault;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import Server.Controller.CAutenticarsi;
import Server.Controller.CSession;
import Server.UI.*;
//import Server.UI.InterfacceConsulente.Contenuto;

public class DefaultInterfacciaGestoreold extends InterfacciaGestore {

	private JPanel login = new JPanel();
	
	private JLabel usernameLabel = new JLabel();
	private JLabel passwordLabel = new JLabel();
	
	private JTextField usernameField = new JTextField();
	private JTextField passwordField = new JTextField();
	private JLabel logo = new JLabel();
	private JLabel payoff = new JLabel();

	
	private CAutenticarsi autenticazione = new CAutenticarsi();
	
	private JButton submit = new JButton();

	
	@Override
	public JPanel createInterfaccia() {
		
		
		login.setLayout(null);
		login.setBounds(0, 0, 1366, 525);
		
		logo.setBounds(50, 20, 150, 150);
		payoff.setBounds(250, 20, 600, 150);
				
		logo.setIcon(new ImageIcon("src\\Server\\UI\\img\\TLLogo.gif"));
		
		payoff.setText("Time Logging");
		Font currentFont = login.getFont();
	    Font newFont = new Font(currentFont.getName(), currentFont.getStyle(), 56);
	    payoff.setFont(newFont);
		
		login.add(logo);
		login.add(payoff);
		
		setLabels();
		setFields();
		setButton();    
		
		login.add(usernameLabel);
		login.add(passwordLabel);
		
		login.add(usernameField);
		login.add(passwordField);
		
		usernameField.setText("4gr");
		passwordField.setText("4gr");
		
		login.add(submit);
		
		
		
		return login;
	}
	
	
	private void setLabels()
	{
		usernameLabel.setText("Username");
		passwordLabel.setText("Password");
		
		usernameLabel.setBounds(250, 100, 300, 100);
		passwordLabel.setBounds(250, 200, 300, 100);
		
		Font currentFont = login.getFont();
	    Font labelFont = new Font(currentFont.getName(), currentFont.getStyle(), 40);

	    usernameLabel.setFont(labelFont);
	    passwordLabel.setFont(labelFont);	    
	}
	
	private void setFields()
	{
		usernameField.setBounds(550, 125, 500, 50);
		passwordField.setBounds(550, 225, 500, 50);
		
		usernameField.setMargin(new Insets(0, 10, 0, 0));
		passwordField.setMargin(new Insets(0, 10, 0, 0));		
		
		Font currentFont = login.getFont();
	    Font fieldFont = new Font(currentFont.getName(), currentFont.getStyle(), 24);    
	    
	    usernameField.setFont(fieldFont);
	    passwordField.setFont(fieldFont);	
	}

	private void setButton()
	{
		submit.setText("Login");			
		submit.setBounds(950, 325, 100, 50);
		
		Font currentFont = login.getFont();
	    Font buttonFont = new Font(currentFont.getName(), currentFont.getStyle(), 24); 		
	    
	    submit.setFont(buttonFont);
	    
	    submit.addActionListener(new ActionListener(){  
	    	@Override  
	    	public void actionPerformed(ActionEvent e) {  
	    		
	    		CSession sessione = CSession.instanza();
	    		autenticazione.autentica(usernameField.getText(), passwordField.getText());
	    		
	    		/*TimeLoggingFrame t = TimeLoggingFrame.instanza();
	    		t.setContenuto( (Contenuto) sessione.getGestoreInterfaccia().createInterfaccia() );
	    		t.refresh();*/
	    		TimeLoggingFrame t = TimeLoggingFrame.instanza();
	    		t.getContentPane().add(sessione.getGestoreInterfaccia().createInterfaccia(),BorderLayout.CENTER );
	    		t.validate();		
	    		t.repaint();
	    		
	    	}});
	}	
	
}
